/// <reference path="layaui/layaUI.max.all.ts" />
/// <reference path="../libs/LayaAir.d.ts" />
/// <reference path="Global.ts" />
/// <reference path="Manager/StageManager.ts" />
/// <reference path="Manager/UIManager.ts" />
/// <reference path="Manager/Web3Manager.ts" />
/// <reference path="Manager/ScreenManager.ts" />
/// <reference path="utils/Msg.ts" />
/// <reference path="type/MateMaskType.ts" />
/// <reference path="utils/LangUtils.ts" />
/// <reference path="type/LanguageType.ts" />
/// <reference path="utils/CookieUtils.ts" />
// 程序入口
import WebGL = laya.webgl.WebGL;
import Stage = Laya.Stage;
import Handler = laya.utils.Handler;
import Pool = laya.utils.Pool;
import Texture = laya.resource.Texture;
import Bitmap = laya.resource.Bitmap;
import Browser = laya.utils.Browser;
import Loader = Laya.Loader;


class LayaAir3D {

    private _car:Car;//车

    constructor()
    {
        //初始化引擎
        Laya3D.init(0, 0, true);

        //初始化舞台宽高
        Laya.init(1920, 1080, WebGL);
        Laya.stage.alignH = Stage.ALIGN_CENTER;
        Laya.stage.alignV = Stage.ALIGN_MIDDLE;

        //适配模式
        Laya.stage.scaleMode = Laya.Stage.SCALE_FULL;
        Laya.stage.screenMode = Laya.Stage.SCREEN_NONE;

        //开启统计信息
        // Laya.Stat.show();

        //加载UI资源
        Laya.loader.load(
            [
                {url:"data/EthCar.bin",type:Loader.BUFFER},
                {url:"res/atlas/main.atlas",type:Loader.ATLAS},
                {url:"res/atlas/comp.atlas",type:Loader.ATLAS},
            ], Handler.create(this,this.onLoaded)
        );
    }

    //资源加载后回调
    private onLoaded(): void {
        Laya.Font.defaultFamily = Global.font;
        LocalData.initDefinitionDic();
        LocalDataManager.getInstance().addLocolData("EthCar");

        //预加载 3D 资源
        Laya.loader.create(
            [
                {url:"res/LayaScene_HYNTest/HYNTest.ls",type:Laya.Scene}
            ], Laya.Handler.create(this,this.onCreateComplete)
        );
    }

    //加载完成
    private onCreateComplete():void{
        //添加3D场景
        Global.scene = Laya.loader.getRes("res/LayaScene_HYNTest/HYNTest.ls");
        Laya.stage.addChild(Global.scene);

        //添加摄像机
        Global.camera = new Laya.Camera();
        Global.scene.addChild(Global.camera);

        //车
        Global.car = new Car();

        StageManager.init();
        UIManager.init();
        // Web3Manager.getInstance().init();

        //显示主页面
        ScreenManager.showMainPage();
    }
}
new LayaAir3D();